const NCHARCODES = 128

abstract class Glyph {
    abstract draw(window: Window, context: GlyphContext): void
    abstract setFont(font: Font, context: GlyphContext): void
    abstract getFont(context: GlyphContext): Font
    abstract first(context: GlyphContext): void
    abstract next(context: GlyphContext): void
    abstract isDone(context: GlyphContext): boolean
    abstract current(context: GlyphContext): Glyph
    abstract insert(glyph: Glyph, context: GlyphContext): void
    abstract remove(context: GlyphContext): void

}
class Font { }
class GlyphContext {
    declare private _index: number
    declare private _fonts: BTree
    next(step: number = 1) { }
    insert(quantity: number = 1) { }
    getFont(): Font { throw new Error("Method not implemented.") }
    setFont(font: Font, span: number = 1) { }
}
class GlyphFactory {
    declare private _character: Character[]
    constructor() {
        this._character = new Array(NCHARCODES).fill(0)
    }
    createCharacter(char: string): Character {
        const asciiCode = char.charCodeAt(0)
        //享元模式的核心，字符不存在时创建，字符存在时返回
        if (!this._character[asciiCode]) {
            this._character[asciiCode] = new Character(char)
        }
        return this._character[asciiCode]
    }
    createRow(): Row {
        return new Row()
    }
    createColumn(): Column {
        return new Column()
    }

}
class Row { }
class Column { }
class BTree { }
class Character extends Glyph {

    declare private _charcode: string
    constructor(char: string) {
        super()
        this._charcode = char
    }
    draw(window: Window, context: GlyphContext): void {
        throw new Error("Method not implemented.")
    }
    setFont(font: Font, context: GlyphContext): void {
        throw new Error("Method not implemented.")
    }
    getFont(context: GlyphContext): Font {
        throw new Error("Method not implemented.")
    }
    first(context: GlyphContext): void {
        throw new Error("Method not implemented.")
    }
    next(context: GlyphContext): void {
        throw new Error("Method not implemented.")
    }
    isDone(context: GlyphContext): boolean {
        throw new Error("Method not implemented.")
    }
    current(context: GlyphContext): Glyph {
        throw new Error("Method not implemented.")
    }
    insert(glyph: Glyph, context: GlyphContext): void {
        throw new Error("Method not implemented.")
    }
    remove(context: GlyphContext): void {
        throw new Error("Method not implemented.")
    }

}


const gf = new GlyphFactory()
const character = gf.createCharacter('a')
const character1 = gf.createCharacter('b')
const character2 = gf.createCharacter('a')

console.log(character === character2);
console.log(character1);
console.log(character2);